package com.liuyucheng.common;

import com.liuyucheng.idea_springboot.IdeaSpringBootApplication;
import com.liuyucheng.idea_springboot.event.UserService;
import com.liuyucheng.idea_springboot.spring.factorybean.MyComplexObject;
import com.liuyucheng.idea_springboot.statemachine.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@Slf4j
@SpringBootTest(classes = IdeaSpringBootApplication.class)
public class CommonTestForSpring {

    @Autowired
    private UserService userService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private MyComplexObject myComplexObject;

    @Test
    public void testFactoryBean(){
        log.info("myComplexObject:{}", myComplexObject);
    }

    @Test
    public void testEvent(){
        userService.registerUser("柳柳");
    }

    @Test
    public void testStateMachine(){
        String orderId = "12345";

        // 模拟订单状态流转
        orderService.pay(orderId);      // 支付
        orderService.deliver(orderId);  // 发货
        orderService.receive(orderId);  // 收货
    }
}
